import java.util.Arrays;

/**
 * @Author 12629
 * @Description：
 */
public class Test {


    public static String myToString(int[] array) {
        String ret = "[";

        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length-1) {
                ret += ",";
            }
        }

        ret += "]";
        return ret;
    }

    /**
     *
     * @param array 指定数组
     * @param val 查找的数据
     * @return 返回下标
     */
    public static int findVal(int[] array,int val) {
        for (int i = 0; i < array.length; i++) {
            if(array[i] == val) {
                return i;
            }
        }
        return -1;
    }

    /**
     *
     * @param array
     * @param val 查找的数据
     * @return
     */
    public static int binarySearch(int[] array,int val) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int mid = (left+right)/2;
            // 1 2 3 4 5   val = 7
            if(array[mid] <val) {
                left = mid+1;
            }else if(array[mid] > val) {
                // 1 2 3 4 5   val = 2
                right = mid-1;
            }else {
                // 1 2 3 4 5   val = 3
                return mid;
            }
        }
        return -1;
    }

    public static void bubbleSort(int[] array) {

        for (int i = 0; i < array.length-1; i++) {

            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]) {
                    swap(array,j,j+1);
                }
            }
        }

    }

    public static void swap(int[] array,int i,int j) {
        int tmp = array[j];
        array[j] = array[i];
        array[i] = tmp;
    }

    public static void reverse(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            swap(array,i,j);
            i++;
            j--;
        }
    }

    public static void main(String[] args) {
        int[] array = {10,20,30,40};

        reverse(array);

        System.out.println(Arrays.toString(array));
    }

    public static void main11(String[] args) {

        int[] array = {10,20,130,40};
        System.out.println("排序前："+Arrays.toString(array));
        bubbleSort(array);
        System.out.println("排序后："+Arrays.toString(array));

        int ret = Arrays.binarySearch(array,140);
        System.out.println(ret);

        /*int ret = binarySearch(array,20);
        System.out.println(ret);*/
    }


    public static int[] test() {
        int[] ret = new int[2];
        ret[0] = 1;
        ret[1] = 2;
        return ret;
    }

    public static void main9(String[] args) {
        int[] array = test();
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    public static void func1(int[] array) {
        array = new int[]{1,2,3,4,5};
    }

    public static void func2(int[] array) {
        array[0] = 10;
    }

    public static void main8(String[] args) {
        int[] array = {10,20,30};
        func2(array);
        print(array);
    }

    public static void print(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
    }

    public static void main7(String[] args) {
        int[] array = {10,20,30};
        print(array);
    }

    public static void main6(String[] args) {
       /* int a = 0;
        System.out.println(a);

        int[] array = null;
        System.out.println(array.length);*/
        int[] array1 = {1,2,3,4};
        array1 = new int[]{1,2,3,4,5,6};
        array1 = new int[]{11,21,31,41,51,61};
    }

    public static void main5(String[] args) {
        int[] array1 = {1,2,3,4};

        int[] array2 = {9,8,7,6};

        System.out.println("交换前array1数组："+Arrays.toString(array1));
        System.out.println("交换前array2数组："+Arrays.toString(array2));

        int[] tmp = array1;
        array1 = array2;
        array2 = tmp;

        System.out.println("交换后array1数组："+Arrays.toString(array1));
        System.out.println("交换后array2数组："+Arrays.toString(array2));

    }

    public static void main4(String[] args) {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;

        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;

        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;

        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }


    public static void main3(String[] args) {
        int[] array = {1,2,3,4};

        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();//for each
        for(int x : array) {
            System.out.print(x+" ");
        }
        System.out.println();

        //把传入的数组 转化为 字符串的形式进行输出
        String ret = Arrays.toString(array);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[100]);
        array[1] = 99;
        System.out.println(array[1]);
    }



    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        //array = {7,8,9,10};

        int n = 10;
        int[] array2 = new int[n];//默认是0

        int[] array3 = new int[]{1,2,3,4,5,6};

        //int arr[] = {1,2,3,4};


        boolean[] flgs = new boolean[3];//默认值是false

        String[] strings = new String[4];
        System.out.println("====");

    }










    public static int max2(int a,int b) {
        return  a > b ? a : b;
    }


    public static int max3(int a,int b,int c) {
        return  max2(a,b) > c ? max2(a,b) : c;
    }


    public static int max(int a,int b) {
        return a > b ? a : b;
    }

    public static int max(int a,int b,int c) {
        return max(a,b) > c ? max(a,b) : c;
    }


}
